import 'package:hive/hive.dart';

part 'marine_protection_model.g.dart';

@HiveType(typeId: 9)
class MarineProtectionModel extends HiveObject {
  @HiveField(0)
  String id;

  @HiveField(1)
  String title;

  @HiveField(2)
  String description;

  @HiveField(3)
  String imageUrl;

  @HiveField(4)
  DateTime startDate;

  @HiveField(5)
  DateTime endDate;

  @HiveField(6)
  String location;

  @HiveField(7)
  List<String> participantIds;

  @HiveField(8)
  String rewardEmojiId;

  MarineProtectionModel({
    required this.id,
    required this.title,
    required this.description,
    required this.imageUrl,
    required this.startDate,
    required this.endDate,
    required this.location,
    List<String>? participantIds,
    required this.rewardEmojiId,
  }) : this.participantIds = participantIds ?? [];

  // 添加参与者
  void addParticipant(String userId) {
    if (!participantIds.contains(userId)) {
      participantIds.add(userId);
    }
  }

  // 检查活动是否进行中
  bool isActive() {
    final now = DateTime.now();
    return now.isAfter(startDate) && now.isBefore(endDate);
  }
}
